package com.ly.ThreadExit;

public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        T2 t2 = new T2();
        t2.start();
        for (int i = 0; i < 20; i++) {
            Thread.sleep(1000);
            System.out.println("主线程吃---------"+i+"包子");
            if (i==5){
                System.out.println("主线程（小弟）让子线程（老大先吃）");
//                t2.join();//这里相当于插队t2执行完毕
//                t2.yield(); //线程礼让
                Thread.yield();
                System.out.println("子（小弟）继续吃---------");
            }
        }
    }
}

class T2 extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("子线程吃了---------"+i+"包子");
        }
    }
}
